<template>
  <card>
    <div class="search-con search-con-top">
      <Button @click="edit(0,0)" class="search-btn" type="primary">
        <Icon type="search"/>&nbsp;添加
      </Button>
    </div>
    <Table border  :columns="columns1" :data="data1"></Table>
    <div style="margin: 10px;overflow: hidden">
          <div style="float: right;">
              <Page :total="total"  @on-change="changePage"></Page>
          </div>
      </div>
  </card>
</template>

<script>
import Bus from '@/libs/bus.js'
import { getOrderInfoList } from "@/api/data";
export default {
  name:'attribute_groups',
  data() {
    return {
      columns1: [
        {
          title: "编号",
          key: "orderId"
        },
        {
          title: "订单类型",
          key: "orderType",
          render: (h, params) => {
            return h("div", [h("div",this.returnOrderType(params.row.orderType))])
          }
        }, 
        {
          title: "金额",
          key: "payment"
        },  
        {
          title: "收货人",
          key: "buyerNick"
        }, 
        {
          title: "收货人手机",
          key: "receiverMobile"
        },     
        {
          title: "支付类型",
          key: "paymentType",
          render: (h, params) => {
            return h("div", [h("div",this.returnPaymentType(params.row.paymentType))])
          }
        },
        {
          title: "下单时间",
          key: "createTime",
          render: (h, params) => {
            return h("div", [h("div",this.format(params.row.createTime))])
          }
        },
        {
          title: "状态",
          key: "status",
          render: (h, params) => {
            return h("div", [h("div",this.returnStatus(params.row.status))])
          }
        },
        {
          title: "操作",
          key: "action",
          width: 150,
          align: "center",
          render: (h, params) => {
            return h("div", [
              h(
                "Button",
                {
                  props: {
                    type: "primary",
                    size: "small"
                  },
                  style: {
                    marginRight: "5px"
                  },
                  on: {
                    click: () => {
                      this.edit(params.index, params.row.attrgroupid);
                    }
                  }
                },
                "编辑"
              ),
              h(
                "Button",
                {
                  props: {
                    type: "error",
                    size: "small"
                  },
                  on: {
                    click: () => {
                      this.delData(params.index, params.row.attrgroupid);
                    }
                  }
                },
                "删除"
              )
            ]);
          }
        }
      ],
      data1: [],
      searchModel: {
        offset: 0,
        limit: 10,
        search:'',
        sort:'',
        order:''
      },
      total: 0
    };
  },
  methods: {
    getData() {
      //获取数据      
      getOrderInfoList(this.searchModel).then(res => {
        this.data1 = res.data.rows;
        this.total = res.data.total;
      });
    },
    changePage(value) {
      //翻页
      debugger;
      var a=(value-1)*10;
      this.searchModel.offset = a;
      this.getData();
    },
    edit(index, attrID) {
      debugger;
      var cateid=this.$route.query.id;
      var id=attrID;
      const route = {
        name: 'attribute_groups_edit',
        query: {
          id,cateid
        },
        meta: {
          title: `编辑产品规格-${id}`
        }
      }
      this.$router.push(route)
    },
    returnOrderType(type){
      switch(type){        
        case 0:
          return '普通订单';
        case 1:
          return '团购订单';
        case 2:
          return '服务订单';
        default:
          return '未知';
      }
    },
    returnPaymentType(type){
      switch(type){        
        case 0:
          return '在线支付';
        case 1:
          return '货到付款';
        default:
          return '未知';
      }
    },
    returnStatus(type){
      switch(type){  
        case 1:
          return '未付款';
        case 2:
          return '已付款';
        case 3:
          return '未发货';
        case 4:
          return '已发货';
        case 5:
          return '交易成功';
        case 6:
          return '交易关闭';
        case 7:
          return '待评价';
        default:
          return '未知';
      }
    },
    format(timestamp)
    {
        var date = new Date(timestamp * 1000);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
        debugger;
        var Y = date.getFullYear() + '-';
        var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
        var D = date.getDate() + ' ';
        var h = date.getHours() + ':';
        var m = date.getMinutes() + ':';
        var s = date.getSeconds();
        return Y+M+D+h+m+s;
    }
  },
  mounted() {
    this.getData(); //初始化数据
    let self = this
    Bus.$on('attribute_groups_edit', (e) => {
      self.message = e
　　　　//console.log(`传来的数据是：${e}`)
      this.getData();
    })
  }
};
</script>
